From da554196056caba8f746e8a911fd3c2081af8f45 Mon Sep 17 00:00:00 2001 From: parkrrrr Date: Thu, 16 Sep 2004 20:16:11 +0000 Subject: [PATCH] various memory leaks from make leaktest --- gpsbabel/defs.h | 1 + gpsbabel/filter_vecs.c | 8 ++++++-- gpsbabel/hsa_ndv.c | 12 +++++++++--- gpsbabel/magproto.c | 10 +++++----- gpsbabel/main.c | 1 + gpsbabel/mapsource.c | 13 +++++++++---- gpsbabel/netstumbler.c | 16 ++++++++++++---- gpsbabel/pcx.c | 15 ++++++++++++++- gpsbabel/tiger.c | 43 ++++++++++++++++++++++++++++++++---------- gpsbabel/vecs.c | 25 +++++++++++++++++++----- 10 files changed, 110 insertions(+), 34 deletions(-) diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index c59e1f1bb..f43d03e89 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -384,6 +384,7 @@ void warning(const char *, ...) ; ff_vecs_t *find_vec(char *, char **); void disp_vecs(void); +void exit_vecs(void); void disp_formats(int version); void printposn(double c, int is_lat); diff --git a/gpsbabel/filter_vecs.c b/gpsbabel/filter_vecs.c index 1ff52928d..1306bb832 100644 --- a/gpsbabel/filter_vecs.c +++ b/gpsbabel/filter_vecs.c @@ -132,8 +132,12 @@ find_filter_vec(char *const vecname, char **opts) void free_filter_vec( filter_vecs_t *fvec ) { - if ( fvec->args && fvec->args->argval && *(fvec->args->argval) ) { - xfree(*(fvec->args->argval)); + arglist_t *ap; + + if ( fvec->args ) { + for ( ap = fvec->args; ap->argstring; ap++) { + if (ap->argval && *ap->argval) xfree(*ap->argval); + } } } diff --git a/gpsbabel/hsa_ndv.c b/gpsbabel/hsa_ndv.c index 4fa3a8361..7e37a67d2 100644 --- a/gpsbabel/hsa_ndv.c +++ b/gpsbabel/hsa_ndv.c @@ -422,8 +422,10 @@ void readVersion4( FILE* pFile) for( Vertex = 0; Vertex < numberOfVerticies; Vertex++) { // read vertex position - if( !readPositionRecord( pFile, &lat2, &lng2, pts2) ) + if( !readPositionRecord( pFile, &lat2, &lng2, pts2) ) { + xfree(wpt_tmp); return; + } wpt_tmp->longitude = lng2; wpt_tmp->latitude = lat2; @@ -432,12 +434,16 @@ void readVersion4( FILE* pFile) // read the class name - if( !readRecord( pFile, EF_CLNM_REC, className) ) + if( !readRecord( pFile, EF_CLNM_REC, className) ) { + xfree( wpt_tmp ); return; + } // read the attributes name - if( !readRecord( pFile, EF_ATTR_REC, attr) ) + if( !readRecord( pFile, EF_ATTR_REC, attr) ) { + xfree( wpt_tmp ); return; + } getAttr(attr, ATTR_OBJECTNAME, &wpt_tmp->shortname, '\x1f'); getAttr(attr, ATTR_USRMRK, &wpt_tmp->description, '\x1f'); diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index b3fa7bfaa..4c9406467 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -35,11 +35,11 @@ static void termwrite(char *obuf, int size); static void mag_readmsg(void); static void mag_handon(void); static void mag_handoff(void); -static void *mkshort_handle; -static char *deficon; -static char *bs; -static char *noack; -static char *nukewpt; +static void *mkshort_handle = NULL; +static char *deficon = NULL; +static char *bs = NULL; +static char *noack = NULL; +static char *nukewpt = NULL; static int route_out_count; static int waypoint_read_count; diff --git a/gpsbabel/main.c b/gpsbabel/main.c index b8b6c4d69..78acd8dfe 100644 --- a/gpsbabel/main.c +++ b/gpsbabel/main.c @@ -290,6 +290,7 @@ main(int argc, char *argv[]) waypt_flush_all(); route_flush_all(); + exit_vecs(); exit_filter_vecs(); #ifdef DEBUG_MEM diff --git a/gpsbabel/mapsource.c b/gpsbabel/mapsource.c index 617dafafb..889905c9f 100644 --- a/gpsbabel/mapsource.c +++ b/gpsbabel/mapsource.c @@ -546,7 +546,7 @@ mps_waypoint_r(FILE *mps_file, int mps_ver, waypoint **wpt, unsigned int *mpscla int lon; int icon; - waypoint *thisWaypoint; + waypoint *thisWaypoint = NULL; double mps_altitude = unknown_alt; double mps_proximity = unknown_alt; double mps_depth = unknown_alt; @@ -634,7 +634,7 @@ mps_waypoint_r(FILE *mps_file, int mps_ver, waypoint **wpt, unsigned int *mpscla /* The following Now done elsewhere since it can be useful to read in and perhaps not add to the list */ /* waypt_add(thisWaypoint); */ - + return; } @@ -1820,11 +1820,15 @@ mps_read(void) fprintf(stderr,"Lost sync with the file reading waypoint - %s\n", wpt->shortname); #endif fseek (mps_file_in, mpsFileInPos + reclen, SEEK_SET); + waypt_free( wpt ); } else { /* only add to the "real" list if a "user" waypoint otherwise add to the private list */ if (mpsWptClass == MPSDEFAULTWPTCLASS) waypt_add(wpt); - else mps_wpt_q_add(&read_route_wpt_head, wpt); + else { + mps_wpt_q_add(&read_route_wpt_head, wpt); + waypt_free( wpt ); + } #ifdef DUMP_ICON_TABLE printf("\t{ %4u, \"%s\" },\n", icon, wpt->shortname); #endif @@ -1972,6 +1976,7 @@ mps_write(void) since we're here because the user didn't request waypoints, this should be acceptable */ mps_waypoint_r(mps_file_temp, mps_ver_temp, &wpt, &mpsWptClass); mps_wpt_q_add(&written_wpt_head, wpt); + waypt_free( wpt ); /* now return to the start of the waypoint data to do a "clean" copy */ fseek(mps_file_temp, tempFilePos, SEEK_SET); @@ -2003,7 +2008,7 @@ mps_write(void) if (recType == 'W') { /* need to be careful that we aren't duplicating a wpt defined from elsewhere */ mps_waypoint_r(mps_file_temp, mps_ver_temp, &wpt, &mpsWptClass); - if (mpsWptClass == MPSDEFAULTWPTCLASS) waypt_add(wpt); + if (mpsWptClass == MPSDEFAULTWPTCLASS) waypt_add(wpt);else waypt_free(wpt); } else break; } diff --git a/gpsbabel/netstumbler.c b/gpsbabel/netstumbler.c index 620cb1815..5f5dba9af 100644 --- a/gpsbabel/netstumbler.c +++ b/gpsbabel/netstumbler.c @@ -30,6 +30,10 @@ static char *nsneicon = "Green Square"; static char *seicon = "Red Diamond"; static char *sneicon = "Green Diamond"; static char *snmac = NULL; +static char *optnseicon = NULL; +static char *optnsneicon = NULL; +static char *optseicon = NULL; +static char *optsneicon = NULL; static void fix_netstumbler_dupes(void); @@ -37,10 +41,10 @@ static void fix_netstumbler_dupes(void); static arglist_t netstumbler_args[] = { - {"nseicon", &nseicon, "Non-stealth encrypted icon name", ARGTYPE_STRING }, - {"nsneicon", &nsneicon, "Non-stealth non-encrypted icon name", ARGTYPE_STRING }, - {"seicon", &seicon, "Stealth encrypted icon name", ARGTYPE_STRING }, - {"sneicon", &sneicon, "Stealth non-encrypted icon name", ARGTYPE_STRING }, + {"nseicon", &optnseicon, "Non-stealth encrypted icon name", ARGTYPE_STRING }, + {"nsneicon", &optnsneicon, "Non-stealth non-encrypted icon name", ARGTYPE_STRING }, + {"seicon", &optseicon, "Stealth encrypted icon name", ARGTYPE_STRING }, + {"sneicon", &optsneicon, "Stealth non-encrypted icon name", ARGTYPE_STRING }, {"snmac", &snmac, "Shortname is MAC address", ARGTYPE_BOOL }, {0, 0, 0, 0} }; @@ -48,6 +52,10 @@ arglist_t netstumbler_args[] = { static void rd_init(const char *fname) { + nseicon = optnseicon?optnseicon:"Red Square"; + nsneicon = optnsneicon?optnsneicon:"Green Square"; + seicon = optseicon?optseicon:"Red Diamond"; + sneicon = optsneicon?optsneicon:"Green Diamond"; file_in = xfopen(fname, "r", MYNAME); } diff --git a/gpsbabel/pcx.c b/gpsbabel/pcx.c index c1cf53197..6ac56afad 100644 --- a/gpsbabel/pcx.c +++ b/gpsbabel/pcx.c @@ -26,19 +26,26 @@ static FILE *file_in; static FILE *file_out; static void *mkshort_handle; +static char *optdeficon = NULL; static char *deficon = "Waypoint"; #define MYNAME "PCX" static arglist_t pcx_args[] = { - {"deficon", &deficon, "Default icon name", ARGTYPE_STRING }, + {"deficon", &optdeficon, "Default icon name", ARGTYPE_STRING }, {0, 0, 0, 0} }; static void rd_init(const char *fname) { + if ( optdeficon ) { + deficon = optdeficon; + } + else { + deficon = "Waypoint"; + } file_in = xfopen(fname, "r", MYNAME); } @@ -51,6 +58,12 @@ rd_deinit(void) static void wr_init(const char *fname) { + if ( optdeficon ) { + deficon = optdeficon; + } + else { + deficon = "Waypoint"; + } file_out = xfopen(fname, "w", MYNAME); mkshort_handle = mkshort_new_handle(); } diff --git a/gpsbabel/tiger.c b/gpsbabel/tiger.c index c30109765..b717f65bd 100644 --- a/gpsbabel/tiger.c +++ b/gpsbabel/tiger.c @@ -33,16 +33,25 @@ static double maxlat, maxlon, minlat, minlon; int rec_cnt; static char *nolabels = NULL; static char *genurl = NULL; +static char *suppresswhite = NULL; +static char *iconismarker = NULL; +static char *snlen = NULL; + static char *margin = "15%"; static char *xpixels = "768"; static char *ypixels = "768"; -static char *snlen = NULL; static char *oldthresh = "14"; static char *oldmarker = "redpin"; static char *newmarker = "greenpin"; static char *unfoundmarker = "bluepin"; -static char *suppresswhite = NULL; -static char *iconismarker = NULL; + +static char *optmargin = NULL; +static char *optxpixels = NULL; +static char *optypixels = NULL; +static char *optoldthresh = NULL; +static char *optoldmarker = NULL; +static char *optnewmarker = NULL; +static char *optunfoundmarker = NULL; int scalev; int short_length; @@ -65,23 +74,23 @@ arglist_t tiger_args[] = { ARGTYPE_BOOL }, {"genurl", &genurl, "Generate file with lat/lon for centering map.", ARGTYPE_OUTFILE }, - {"margin", &margin, "Margin for map. Degrees or percentage.", + {"margin", &optmargin, "Margin for map. Degrees or percentage.", ARGTYPE_FLOAT}, {"snlen", &snlen, "Max shortname length when used with -s.", ARGTYPE_INT}, - {"oldthresh", &oldthresh, "Days after which points are considered old.", + {"oldthresh", &optoldthresh, "Days after which points are considered old.", ARGTYPE_INT}, - {"oldmarker", &oldmarker, "Marker type for old points.", + {"oldmarker", &optoldmarker, "Marker type for old points.", ARGTYPE_STRING}, - {"newmarker", &newmarker, "Marker type for new points.", + {"newmarker", &optnewmarker, "Marker type for new points.", ARGTYPE_STRING}, {"suppresswhite", &suppresswhite, "Suppress whitespace in generated shortnames", ARGTYPE_BOOL }, - {"unfoundmarker", &unfoundmarker, "Marker type for unfound points.", + {"unfoundmarker", &optunfoundmarker, "Marker type for unfound points.", ARGTYPE_STRING}, - {"xpixels", &xpixels, "Width in pixels of map.", + {"xpixels", &optxpixels, "Width in pixels of map.", ARGTYPE_INT}, - {"ypixels", &ypixels, "Height in pixels of map.", + {"ypixels", &optypixels, "Height in pixels of map.", ARGTYPE_INT}, {"iconismarker", &iconismarker, "The icon description is already the marker", ARGTYPE_BOOL }, @@ -96,6 +105,13 @@ arglist_t tiger_args[] = { static void rd_init(const char *fname) { + margin = optmargin?optmargin:"15%"; + xpixels = optxpixels?optxpixels:"768"; + ypixels = optypixels?optypixels:"768"; + oldthresh = optoldthresh?optoldthresh:"14"; + oldmarker = optoldmarker?optoldmarker:"redpin"; + newmarker = optnewmarker?optnewmarker:"greenpin"; + unfoundmarker = optunfoundmarker?optunfoundmarker:"bluepin"; file_in = xfopen(fname, "r", MYNAME); mkshort_handle = mkshort_new_handle(); } @@ -110,6 +126,13 @@ rd_deinit(void) static void wr_init(const char *fname) { + margin = optmargin?optmargin:"15%"; + xpixels = optxpixels?optxpixels:"768"; + ypixels = optypixels?optypixels:"768"; + oldthresh = optoldthresh?optoldthresh:"14"; + oldmarker = optoldmarker?optoldmarker:"redpin"; + newmarker = optnewmarker?optnewmarker:"greenpin"; + unfoundmarker = optunfoundmarker?optunfoundmarker:"bluepin"; file_out = xfopen(fname, "w", MYNAME); thresh_days = strtod(oldthresh, NULL); } diff --git a/gpsbabel/vecs.c b/gpsbabel/vecs.c index fc66634c1..c66f92b73 100644 --- a/gpsbabel/vecs.c +++ b/gpsbabel/vecs.c @@ -301,6 +301,24 @@ vecs_t vec_list[] = { } }; +void +exit_vecs( void ) +{ + vecs_t *vec = vec_list; + while ( vec->vec ) { + arglist_t *ap; + if ( vec->vec->args ) { + for ( ap = vec->vec->args; ap->argstring; ap++ ) { + if ( ap->argval && *ap->argval ) { + xfree(*ap->argval); + *ap->argval = NULL; + } + } + } + vec++; + } +} + ff_vecs_t * find_vec(char *const vecname, char **opts) { @@ -324,11 +342,8 @@ find_vec(char *const vecname, char **opts) if (vec->vec->args) { for (ap = vec->vec->args; ap->argstring; ap++){ - void *av; - av = get_option(*opts, ap->argstring); - if (av) { - *ap->argval = av; - } + if ( *ap->argval ) xfree(*ap->argval); + *ap->argval = get_option(*opts, ap->argstring); } } } else { -- 2.30.2